package cn.highedu.config;

import cn.highedu.service.HelloService;
import cn.highedu.service.HelloServiceImpl;
import cn.highedu.service.TypicalHelloService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
// ConditionalOnClass: 当HelloService这个类在类路径中时，才会初始化这个配置类
@ConditionalOnClass(HelloService.class)
public class HelloAutoConfig {

    // ConditionalOnMissingBean: 当容器中没有指定HelloService类型的Bean时，
    // 才会初始化这个TypicalHelloService
    @ConditionalOnMissingBean(HelloService.class)
    @Bean
    HelloService helloService(){
        return new TypicalHelloService();
    }
}
